<!-- eslint-disable vue/multi-word-component-names -->
// eslint-disable-next-line vue/multi-word-component-names
<template>
  <div class="zhishi">
    <header>
      <a-breadcrumb class="onee">
        <a-breadcrumb-item></a-breadcrumb-item>
        <router-link to="./LeftChild_1">工作台</router-link>
        <a-breadcrumb-item>知识小册</a-breadcrumb-item>
      </a-breadcrumb>
    </header>
    <main>
      <div class="headtwo">
        <div class="aa">
          <div class="a1">
            名称:
            <input placeholder="请输入知识库名称" v-model="state.searchci" />
          </div>
          <div class="a2">
            状态:
            <select>
              <option>已发布</option>
              <option>草稿</option>
            </select>
          </div>
        </div>
        <div class="bb">
          <div class="b1">
            <button @click="search()">搜索</button>
            <button @click="chongzhi()">重置</button>
          </div>
        </div>
      </div>
      <div class="headthree">
        <!-- 数据 -->
        <div class="book">
          <div class="book1">
            <button @click="showDrawer">+新建</button>
            <a-drawer
              v-model:visible="visible"
              class="custom-class"
              style="opacity: 0.3"
              title="更新知识库"
              placement="right"
              @after-visible-change="afterVisibleChange"
            >
              <span>
                名称
                <a-input
                  placeholder="Basic usage"
                  style="width: 88%; margin-left: 5px"
                />
              </span>
              <span style="margin-top: 20px; display: block">
                描述
                <a-textarea
                  placeholder="textarea with clear icon"
                  allow-clear
                  style="width: 88%; margin-left: 10px"
                />
              </span>
              <span style="margin-top: 20px; display: block">
                评论
                <a-switch v-model:checked="checked" />
              </span>
              <span style="margin-top: 20px; display: block">
                封面
                <a-input
                  type="text"
                  style="width: 88%; height: 100px; margin-left: 5px"
                />
                <a-input
                  type="file"
                  style="
                    width: 88%;
                    height: 36px;
                    margin-left: 38px;
                    margin-top: 10px;
                  "
                />
              </span>
            </a-drawer>
          </div>
          <div class="book2">
            <div
              class="forxunhuan"
              v-for="(item, index) in state.list"
              :key="index"
            >
              <div class="oneee">
                <img :src="item.cover" />
                <p>{{ item.title }}</p>
              </div>
              <div class="twooo">
                <div class="b1">
                  <button><edit-outlined /></button>
                </div>
                <div class="b1">
                  <a-button @click="info"><cloud-upload-outlined /></a-button>
                </div>
                <div class="b3">
                  <a-button type="primary" @click="showDrawer">
                    <setting-outlined />
                  </a-button>
                </div>
                <a-drawer
                  v-model:visible="visible"
                  class="custom-class"
                  style="opacity: 0.3"
                  58
                  title="更新知识库"
                  placement="right"
                  @after-visible-change="afterVisibleChange"
                >
                  <span>
                    名称
                    <a-input
                      placeholder="Basic usage"
                      style="width: 88%; margin-left: 5px"
                    />
                  </span>
                  <span style="margin-top: 20px; display: block">
                    描述
                    <a-textarea
                      placeholder="textarea with clear icon"
                      allow-clear
                      style="width: 88%; margin-left: 10px"
                    />
                  </span>
                  <span style="margin-top: 20px; display: block">
                    评论
                    <a-switch v-model:checked="checked" />
                  </span>

                  <span style="margin-top: 20px; display: block">
                    封面
                    <a-input
                      type="text"
                      style="width: 88%; height: 100px; margin-left: 5px"
                    />
                    <a-input
                      type="file"
                      style="
                        width: 88%;
                        height: 36px;
                        margin-left: 38px;
                        margin-top: 10px;
                      "
                    />
                  </span>
                </a-drawer>
                <div class="b4">
                  <a-popconfirm class="b6">
                    <span @click="deiler(index)"><delete-outlined /></span>
                  </a-popconfirm>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- 分页 -->
        <div class="example">
          <a-pagination :total="100" show-size-changer />
        </div>
      </div>
    </main>
    <footer></footer>
  </div>
</template>
<script lang="ts">
import { defineComponent, reactive, ref, onMounted } from 'vue'
import {
  EditOutlined,
  CloudUploadOutlined,
  SettingOutlined,
  DeleteOutlined
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import axios from 'axios'
export default defineComponent({
  components: {
    EditOutlined,
    CloudUploadOutlined,
    SettingOutlined,
    DeleteOutlined
  },
  setup() {
    //按钮
    const aa = localStorage.getItem('role')
    console.log(aa)
    const checked = ref<boolean>(false)
    const visible = ref<boolean>(false)
    const afterVisibleChange = (bool: boolean) => {
      console.log('visible', bool)
    }
    const showDrawer = () => {
      visible.value = true
    }
    //删除
    const deiler = (index: any) => {
      state.list.splice(index, 1)
    }
    //搜索
    const search = () => {
      const searchItem = state.list.filter((v: any) => {
        return v.title.includes(state.searchci)
      })
      state.list = searchItem
    }
    // 重置
    const chongzhi = () => {
      state.searchci = ''
    }
    const info = () => {
      if (aa == '管理员') {
        showDrawer()
      } else {
        message.info('访客无权登录')
      }
    }
    const confirm = () => {
      message.success('访客无权进行该操作')
    }
    let state: any = reactive({
      list: [
        {
          cover: '',
          title: '',
          searchci: ''
        }
      ]
    })
    onMounted(() => {
      axios.get('https://creationapi.shbwyz.com/api/Knowledge').then((res) => {
        state.list = res.data.data[0]
        console.log(res.data.data[0])
      })
    })
    return {
      state,
      confirm,
      afterVisibleChange,
      showDrawer,
      visible,
      search,
      chongzhi,
      checked,
      info,
      deiler
    }
  }
})
</script>

<style lang="scss">
.zhishi {
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  overflow-y: scroll;
}
header {
  width: 100%;
  height: 80px;
  background-color: #fff;
  border-top: 1px solid #ccc;
  position: sticky;
  top: 0%;
  .ant-breadcrumb {
    height: 100px;
  }
  .onee {
    margin-top: 30px;
    margin-left: 30px;
  }
}
main {
  flex: 1;
  width: 100%;
  height: auto;
  // background-color: #ccc;

  .headtwo {
    width: 95%;
    height: 160px;
    background-color: #fff;
    margin-left: 2%;
    margin-top: 1.5%;
    .aa {
      width: 100%;
      height: 80px;
      display: flex;
      .a1 {
        margin-left: 50px;
        padding-top: 50px;
        font-size: 18px;
        input {
          border: 1px solid #ccc;
          margin-left: 5px;
          border-radius: 10px;
          text-indent: 10px;
          outline: 0;
        }
      }
      .a2 {
        margin-left: 50px;
        padding-top: 45px;
        font-size: 18px;
        select {
          width: 207px;
          height: 32.28px;
          border: 1px solid #ccc;
          margin-left: 5px;
          border-radius: 10px;
          outline: 0;
        }
      }
    }
    .bb {
      .b1 {
        display: flex;
        margin-top: 40px;
        margin-left: 80%;

        button {
          width: 100px;
          height: 30px;
          background-color: #0188fb;
          margin-left: 20px;
          border: none;
          color: #fff;
        }
      }
    }
  }
  .headthree {
    width: 95%;
    height: auto;
    background-color: #fff;
    margin-left: 2%;
    margin-top: 1.5%;
    .book {
      width: 100%;
      height: auto;
      display: flex;
      flex-direction: column;
      margin-bottom: 20px;
      .book1 {
        width: 100%;
        height: 30px;
        button {
          width: 100px;
          height: 28px;
          margin-left: 92%;
          margin-top: 10px;
          color: #fff;
          border: none;
          background-color: #0188fb;
        }
      }
      .book2 {
        width: 100%;
        height: 500px;
        margin-top: 30px;
        display: flex;
        flex-wrap: wrap;
        .forxunhuan {
          width: 200px;
          height: 260px;
          border: 1px #f0f0f0 solid;
          margin-left: 16px;
          margin-top: 10px;
          .oneee {
            width: 100%;
            height: 210px;
            border-bottom: 1px solid #f0f0f0;
            img {
              width: 100%;
              height: 150px;
            }
          }
          .twooo {
            width: 100%;
            height: 50px;
            display: flex;
            .ant-drawer-mask {
              opacity: 0.3;
            }
            .b1 {
              width: 25%;
              height: 100%;
              border-right: 1px solid #f0f0f0;
              button {
                border: none;
                background-color: #fff;
                width: 90%;
                height: 90%;
              }
            }
            .b3 {
              width: 25%;
              height: 100%;
              border-right: 1px solid #f0f0f0;
              .ant-btn-primary {
                background-color: #fff;
                color: #000;
                border: none;
                height: 95%;
                .ant-btn {
                  width: 95%;
                  height: 100%;
                  border: none;
                  span {
                    margin-left: 15px;
                    margin-top: 15px;
                  }
                }
              }
            }
            .b4 {
              width: 25%;
              height: 100%;
              border-right: 1px solid #f0f0f0;
              .b6 {
                color: #000;
                span {
                  margin-left: 15px;
                  margin-top: 15px;
                }
              }
            }
          }
        }
      }
    }
    .example {
      margin-left: 70%;
      margin-top: 50px;
    }
  }
}
footer {
  width: 90%;
  height: 100px;
  background-color: #934396;
}
.ant-drawer-content-wrapper {
  width: 500px;
}
</style>
